package com.itconnect.musica.views;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.google.analytics.tracking.android.EasyTracker;
import com.itconnect.inc

.musica.R;


public class MainActivity extends Activity {

	private com.itconnect.musica.composants.CustomWebView webView;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_layout);
		webView = (com.itconnect.musica.composants.CustomWebView) findViewById(R.id.webView1);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.setWebViewClient(new WebViewClient() {
			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				view.setVisibility(View.GONE);

			}

			@Override
			public void onPageFinished(WebView view, String url) {
				webView.loadUrl("javascript:(function() { "
						+ "var head  = document.getElementsByTagName('head')[0];"
						+ "var link  = document.createElement('link');" +

						"link.rel  = 'stylesheet';" + "link.type = 'text/css';"
						+ "link.href = 'https://www.dropbox.com/s/kfksgtampvdqajl/style.css?dl=1';"
						+ "link.media = 'all';" + "head.appendChild(link);"
						+ "})()");
				super.onPageFinished(view, url);
				
				view.setVisibility(View.VISIBLE);

			}

			@Override
			public void onReceivedError(WebView view, int errorCode,
					String description, String failingUrl) {
				view.loadUrl("file:///android_asset/noconnction.html");
				super.onReceivedError(view, errorCode, description, failingUrl);
			}
		});
		webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
		if (savedInstanceState != null)
			webView.restoreState(savedInstanceState);
		else
			webView.loadUrl(getResources().getString(R.string.path_url));

	}
	@Override
	public void onBackPressed() {
		webView.goBack();
	}
	
	  @Override
	  public void onStart() {
	    super.onStart();
	    EasyTracker.getInstance(this.getApplicationContext()).activityStart(this); // Add this method.
	  }

	  @Override
	  public void onStop() {
	    super.onStop();
	    EasyTracker.getInstance(this.getApplicationContext()).activityStop(this); // Add this method.
	  }

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		 super.onSaveInstanceState(outState);
		webView.saveState(outState);
	}
	@Override
	  protected void onRestoreInstanceState(Bundle savedInstanceState)
	  {
	    super.onRestoreInstanceState(savedInstanceState);
	    webView.restoreState(savedInstanceState);
	  }

}